$(function () {
    $("header").load("header.html")

    
    id = localStorage.getItem("lqtoken").split(";")[1].split(":")[1]
    $.get("api/myArticleList?userId=" + id, function (data) {
        for (var i = 0; i < data.length; i++) {
            $("#myli").append(`
            
            <li>
            <a href="./blog.html?id=${data[i]._id}" style="text-decoration: none;">
            <div style="background-color: aquamarine;">
            <div class="title">标题</div>
            <div class="desc">文章描述</div>
            </div>
            </a>
            <div><span style="color: blue; cursor: pointer;" id="update" data-del="${data[i]._id}">更新</span> <span data-bs-toggle="modal" data-bs-target="#exampleModal" style="color: red; cursor: pointer;" class="del"  data-del="${data[i]._id}">删除</span></div>
        </li>

            `)
            
            $(".title").eq(i).text(data[i].title)
            $(".desc").eq(i).text(data[i].desc)
        }
        $(".del").click(function() {
            // 获取当前点击的.del元素上存储的id
            var id = $(this).data("del");
            $("#verfiy").attr("data-del", id)
        });
        $("#verfiy").click(function() {
            // 获取当前点击的.del元素上存储的id
            var id = $(this).data("del");
            $.get("api/deleteArticle?id=" + id, function(data) {
            });
            window.location.href = "./my.html";
        });
        if ($("#myli").text() == "") {
            $("#myli").append(
                `
                    <div>你还没有发布文章，<a href="./write.html">快去写一篇吧！</a></div>            
                `
            )
        }
    })


})


